#include "StdAfx.h"
#include "MainFrame.h"


BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	ON_WM_CREATE()
	ON_WM_CLOSE()
END_MESSAGE_MAP()


CMainFrame::CMainFrame() :
m_DocumentManager(m_Document),
m_FileManager(m_Document, m_DocumentManager)
{
}


BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void *pExtra, AFX_CMDHANDLERINFO *pHandlerInfo)
{
	if (m_FileManager.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
	{
		return TRUE;
	}

	if (m_DocumentManager.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
	{
		return TRUE;
	}

	return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIFrameWnd::OnCreate(lpCreateStruct) != 0)
	{
		return -1;
	}

	if (!m_wndStatusBar.Create(this))
	{
		return -1;
	}

	UINT aIDs[1] = {0};
	VERIFY(m_wndStatusBar.SetIndicators(aIDs, 1));

	if (!m_wndToolbar.CreateEx(
		this,
		TBSTYLE_FLAT,
		WS_CHILD |
		WS_VISIBLE |
		CBRS_TOP |
		CBRS_GRIPPER |
		CBRS_FLYBY |
		CBRS_SIZE_DYNAMIC
		))
	{
		return -1;
	}
	if (!m_wndToolbar.LoadToolBar(IDR_MAINFRAME))
	{
		return -1;
	}

	if (!m_wndTreeView.Create(
		this,
		IDD_PROJECTTREE,
		WS_CHILD |
		WS_VISIBLE |
		CBRS_LEFT |
		CBRS_SIZE_DYNAMIC,
		1
		))
	{
		return -1;
	}

	EnableDocking(CBRS_ALIGN_ANY);

	m_wndToolbar.EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolbar);

	m_wndTreeView.EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndTreeView);

	return 0;
}

void CMainFrame::OnClose()
{
	if (m_FileManager.CreateNew())
	{
		CFrameWnd::OnClose();
	}
}
